package org.applet.game.app.rpg.widgets;

import java.awt.Event;
import java.awt.image.BufferedImage;

import org.applet.game.app.rpg.resource.MagicResource;
import org.applet.game.app.rpg.scene.JXScene;
import org.applet.game.framework.component.FrameButton;
import org.applet.game.framework.component.ImageButton;
import org.applet.game.framework.component.Panel;
import org.applet.game.framework.core.Container;
import org.applet.game.framework.util.ImageLoader;

public class SceneToolbar extends Container {


	//BufferedImage magicTitles = ImageLoader.loadImage("images/magic/magicTitle.png");
	Panel bottomMenuCenter = new Panel(ImageLoader.loadImage("image/plate/BottomMenuCenter.png"));
	Panel buttomMenu = new Panel(ImageLoader.loadImage("image/plate/BottomMenu.png"));
	FrameButton rightButton;
	FrameButton leftButton;
	
	public SceneToolbar()
	{
		this.width = buttomMenu.getWidth();
		this.height = buttomMenu.getHeight();
		setLocation(0, 0);

		add(buttomMenu);
		
		leftButton = new FrameButton(MagicResource.getMagicTitle(2), 0, 0, 27, 27){
			@Override
			public boolean mouseDown(Event e) {
				return false;
			}
		};
		add(leftButton);
		leftButton.setX(402);
		leftButton.setY(6);

		rightButton = new FrameButton(MagicResource.getMagicTitle(0), 0, 0, 27, 27){
			@Override
			public boolean mouseDown(Event e) {
				((JXScene)getScene()).showMagicSelector(getX(), getY()-87);
				return false;
			}
		};
		add(rightButton);
		rightButton.setX(437);
		rightButton.setY(6);
		
		add(bottomMenuCenter);
		bottomMenuCenter.setX(393);
		
		int positionY = 30;
		int posiOffsetx = 0;
		for(int i=0;i<9;i++)
		{
			if(i==1)
				posiOffsetx++;
			if(i==4)
				posiOffsetx++;
			if(i==7)
				posiOffsetx++;
			int iname = 13+i*2;
			final ImageButton button1 = new ImageButton(ImageLoader.loadImage("image/icon/"+iname+".png"), ImageLoader.loadImage("image/icon/"+(++iname)+".png"), ImageLoader.loadImage("image/icon/"+iname+".png")){
				@Override
				public boolean mouseDown(Event e) {
					//System.out.println(this.getName());
					((JXScene)getScene()).showItemBox();
					return false;
				}
			};
			add(button1);
			button1.setName("name"+i);
			button1.setLocation(buttomMenu.getX()+481+i*22+posiOffsetx, positionY);
		}
	}
	
	public void setRightButtonImage(BufferedImage image)
	{
		rightButton.setImage(image);
	}
	
	@Override
	public void init() {
		super.init();
	}
	
	
}
